package com.beam.impl.bookmark;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.beam.base.BaseAction;
import com.beam.base.Service;
import com.beam.util.Pager;
@Controller
@RequestMapping( "/bookmark" )
public class BookmarkAction extends BaseAction<Bookmark>{
	
	
	@Autowired
	BookmarkService service;
	
	@Override
	public Service<Bookmark> getService(){
		return service;
	}
	
	@RequestMapping("list")
	public String list(Pager pager , Model model ){
		model.addAttribute( "models" , service.findByUser(pager, getSessionUser().getId() ) );
		return forward( "list" );
	}
	
	@RequestMapping("save")
	@ResponseBody
	public boolean save(Bookmark bookmark) {
		bookmark.setUserId( getSessionUser().getId() );
		return getService().saveOrUpdate( bookmark );
		
	}
	
	@RequestMapping("sort")
	public String sort(Integer id,boolean upper, Model model ){
		service.sort(id, upper, getSessionUser().getId() );
		return redirect( "list" );
	}
	
	@RequestMapping( "delete" )
	public String delete(Integer id , Model model ){
		return super.delete( id , model );
	}
}


